/**
 * Created by afer on 2017/7/3.
 */



var XXXModel = require('../Dao/admindao');
var JsonModel = require('../config/jsonModel');
var MD5 = require('../tool/MD5S');

module.exports = function(app) {

    app.get('/install', function (req, res) {
        var model = new JsonModel.JsonModel();
        model.status = 0;
        var xxx = {
            username: 'superAdmin',
            passwords: MD5.md5('112233afer'),
            level: 0
        };
        XXXModel.addAdmin(xxx)
            .then(function (result) {
                model.content = result.ops[0];
                model.status = 1;
                model.msg = '添加成功!';
                res.send(model);
            }).catch(function (error) {
            model.content = {};
            if (error.message.match('E11000 duplicate key')) {
                model.msg = '用户名重复!';
            } else {
                model.msg = error.message;
            }
            res.send(model);
        });
    });

}